package com.okwanshiwu.payment.wxUtil;

import org.apache.log4j.Logger;
import java.io.InputStream;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Properties;

/**
 * 微信支付参数实体类
 *
 * static的私有变量为从配置文件中进行获取，直接在加载类的时候进行初始化
 */
public class WxProperties {

	private static Logger logger = Logger.getLogger(WxProperties.class);

	public static String APPID;
	public static String MCH_ID;
	public static String APIKEY;
	public static String REFUND_URL;
	public static String ORDERQUERY_URL;
	public static String NOTIFY_URL;
	private String device_info;
	private String nonce_str;
	private String sign;
	private String body;//商品描述
	private String detail;//商品详情
	private String attach;//附加数据
	private String out_trade_no;
	private String fee_type;//币种类型 CNY
	private int total_fee;
	private String spbill_create_ip;
	private String time_start;
	private String goods_tag;
	private String trade_type;
	private String product_id;
	private String limit_pay;
	private String openid;

	//读取配置文件，初始化一部分参数
	static {
		try{
			InputStream is = WxProperties.class.getResourceAsStream("/common.properties");
			Properties properties = new Properties();
			properties.load(is);
			APPID = properties.getProperty("appid");
			MCH_ID = properties.getProperty("mch_id");
			NOTIFY_URL = properties.getProperty("notify_url");
			APIKEY = properties.getProperty("apikey");
			REFUND_URL = properties.getProperty("refundUrl");
			ORDERQUERY_URL = properties.getProperty("orderqueryUrl");
		}catch(Exception ex){
			logger.debug("加载配置文件："+ex.getMessage());
		}
	}
	//构造方法进行相关参数的初始化
	public WxProperties() {
	}
	public WxProperties(String body,String out_trade_no,int price,String spbill_create_ip,String trade_type,String nonce_str) {
		this.body = body;
		this.out_trade_no = out_trade_no;
		this.total_fee = price;
		this.spbill_create_ip = spbill_create_ip;
		this.trade_type = trade_type;
		this.nonce_str = nonce_str;
	}
	public WxProperties(String body,String attach,String out_trade_no,int price,String spbill_create_ip,String trade_type,String nonce_str) {
		this.body = body;
		this.attach = attach;
		this.out_trade_no = out_trade_no;
		this.total_fee = price;
		this.spbill_create_ip = spbill_create_ip;
		this.trade_type = trade_type;
		this.nonce_str = nonce_str;
	}

	public String getDevice_info() {
		return device_info;
	}
	public String getNonce_str() {
		return nonce_str;
	}
	public String getSign() {
		return sign;
	}
	public String getBody() {
		return body;
	}
	public String getDetail() {
		return detail;
	}
	public String getAttach() {
		return attach;
	}
	public String getOut_trade_no() {
		return out_trade_no;
	}
	public String getFee_type() {
		return fee_type;
	}
	public int getTotal_fee() {
		return total_fee;
	}
	public String getSpbill_create_ip() {
		return spbill_create_ip;
	}
	public String getTime_start() {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
		return sdf.format(new Date());
	}
	public String getGoods_tag() {
		return goods_tag;
	}
	public String getTrade_type() {
		return trade_type;
	}
	public String getProduct_id() {
		return product_id;
	}
	public String getLimit_pay() {
		return limit_pay;
	}
	public String getOpenid() {
		return openid;
	}

	public void setDevice_info(String device_info) {
		this.device_info = device_info;
	}
	public void setNonce_str(String nonce_str) {
		this.nonce_str = nonce_str;
	}
	public void setSign(String sign) {
		this.sign = sign;
	}
	public void setBody(String body) {
		this.body = body;
	}
	public void setDetail(String detail) {
		this.detail = detail;
	}
	public void setAttach(String attach) {
		this.attach = attach;
	}
	public void setOut_trade_no(String out_trade_no) {
		this.out_trade_no = out_trade_no;
	}
	public void setFee_type(String fee_type) {
		this.fee_type = fee_type;
	}
	public void setTotal_fee(int total_fee) {
		this.total_fee = total_fee;
	}
	public void setSpbill_create_ip(String spbill_create_ip) {
		this.spbill_create_ip = spbill_create_ip;
	}
	public void setGoods_tag(String goods_tag) {
		this.goods_tag = goods_tag;
	}

	public void setTrade_type(String trade_type) {
		this.trade_type = trade_type;
	}
	public void setProduct_id(String product_id) {
		this.product_id = product_id;
	}
	public void setLimit_pay(String limit_pay) {
		this.limit_pay = limit_pay;
	}
	public void setOpenid(String openid) {
		this.openid = openid;
	}

}
